package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysMenuService;
import com.atguigu.spzx.model.entity.system.SysMenu;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.system.SysMenuVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author LT
 * @create 2024-03-14-11:46
 */
@RestController
@Tag(name = "菜单管理模块")
@RequestMapping("/admin/system/menu")
public class SysMenuController {

    @Resource
    SysMenuService sysMenuService;

    @GetMapping("/listNestedMenus")
    public Result listNestedMenus(){
        List<SysMenu> sysMenuList = sysMenuService.listNestedMenus();
        return Result.ok(sysMenuList);
    }

    @DeleteMapping("/deleteMenus/{id}")
    public Result DeleteMenus(@PathVariable("id") Long id){
        sysMenuService.DeleteMenus(id);
        return Result.ok();
    }

    @PostMapping("/saveMenu")
    public Result SaveMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.saveMenu(sysMenu);
        return Result.ok();
    }

    @GetMapping("/FindMenuById/{id}")
    public Result FindMenuById(@PathVariable("id") Long id){
        SysMenu sysMenu = sysMenuService.FindMenuById(id);
        return Result.ok(sysMenu);
    }

    @PutMapping("/updateMenu")
    public Result UpdateMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.UpdateMenu(sysMenu);
        return Result.ok();
    }

    @GetMapping("/getMenusAndAssignedMenuIds/{id}")
    public Result GetMenusAndAssignedMenuIds(@PathVariable("id") Long id){
        Map<String,Object> map = sysMenuService.getMenusAndAssignedMenuIds(id);
        return Result.ok(map);
    }

    @GetMapping("/listUserMenu")
    public Result GetMenus(){
        List<SysMenuVo> sysMenuVos = sysMenuService.getMenus();
        return Result.ok(sysMenuVos);
    }

}
